Skip to main content

50.10.5 Writing Custom InfoContributors

50.10.5 编写自定义的InfoContributor

你可以注册实现了InfoContributor接口的Spring bean,来提供自定义应用信息。以下示例暴露一个只有单个值的example实体:

import java.util.Collections;

import org.springframework.boot.actuate.info.Info;
import org.springframework.boot.actuate.info.InfoContributor;
import org.springframework.stereotype.Component;

@Component
public class ExampleInfoContributor implements InfoContributor {

@Override
public void contribute(Info.Builder builder) {
builder.withDetail("example",
Collections.singletonMap("key", "value"));
}

}

如果到达info端点,你应该可以看到包含以下实体的响应:

{
"example": {
"key" : "value"
}
}